package com.ssm.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class MyHandlerException implements HandlerExceptionResolver{

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception exception) {
		//MyException myException = (MyException) exception;
		
		ModelAndView andView = new ModelAndView();
		andView.addObject("message", exception.getMessage());
		andView.setViewName("error");
		return andView;
		/*取异常堆栈：
        try {
			
		} catch (Exception e) {
			StringWriter s = new StringWriter();
			PrintWriter printWriter = new PrintWriter(s);
			e.printStackTrace(printWriter);
			s.toString();
		}*/

	}

}
